package se.sll.itintegration.catalogue.gui.service;

import org.apache.shiro.authc.credential.DefaultPasswordService;
import org.apache.shiro.crypto.hash.DefaultHashService;
import org.apache.shiro.crypto.hash.Sha512Hash;
import org.apache.shiro.util.SimpleByteSource;

/**
 *
 * @author khaleddaham
 */
class SecurityUtils {

    public static final int HASH_ITERATIONS = 250000;
    public static final String HASH_ALGORITHM_NAME = Sha512Hash.ALGORITHM_NAME;
    /** Same salt as in shiro.ini, but NOT base64-encoded. */
    public static final String PRIVATE_SALT = "POc0cz3TGiXamfYCr065";

    static boolean isSuperAdmin() {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    
    static String createPasswordHash(String clearText) {
        DefaultHashService hashService = new DefaultHashService();
        hashService.setHashIterations(HASH_ITERATIONS);
        hashService.setHashAlgorithmName(HASH_ALGORITHM_NAME);
        hashService.setPrivateSalt(new SimpleByteSource(PRIVATE_SALT));
        hashService.setGeneratePublicSalt(true);

        DefaultPasswordService passwordService = new DefaultPasswordService();
        passwordService.setHashService(hashService);

        return passwordService.encryptPassword(clearText);
    }
}
